import request from "@/utils/request";
import { AxiosPromise } from "axios";
import { DictQuery, DictForm, DictPageResult } from "./types";

/**
 * 获取字典类型的数据项
 * 用于字典组件
 * @param pcode 字典类型编码
 */
export function getDictOptions(pcode: string): AxiosPromise<DictForm[]> {
  const params = { code: pcode };
  return request({
    url: "admin/dict/children",
    method: "get",
    params,
  });
}

/**
 * 字典分页列表
 */
export function getDictPage(
  queryParams: DictQuery
): AxiosPromise<DictPageResult> {
  return request({
    url: "admin/dict/list",
    method: "get",
    params: queryParams,
  });
}

/**
 * 新增字典
 *
 * @param data
 */
export function saveDict(data: DictForm) {
  return request({
    url: "admin/dict/save",
    method: "post",
    data,
  });
}

/**
 * 删除字典
 *
 * @param ids 字典项ID，多个以英文逗号(,)分割
 */
export function deleteDict(ids: string[]) {
  return request({
    url: "admin/dict/del",
    method: "post",
    data: ids,
  });
}
